<template>
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="120px">
      <el-form-item label="系统名称">
        <el-input v-model="form.siteName"></el-input>
      </el-form-item>
      <el-form-item label="域名备案号(ICP)">
        <el-input v-model="form.siteIcp"></el-input>
      </el-form-item>
      <el-form-item label="Banner">
        <el-input v-model="form.siteBanner" placeholder="多个URL以英文的逗号分隔"></el-input>
      </el-form-item>
      <el-form-item label="公告">
        <el-input type="textarea" v-model="form.siteNotice"></el-input>
      </el-form-item>
      <el-form-item label="描述">
        <el-input type="textarea" v-model="form.siteDescription"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import { getSettings, editSettings } from '../../api/options'

  export default {
    name: 'Settings',
    data() {
      return {
        loading: false,
        form: {
          siteName: '',
          siteIcp: '',
          siteBanner: '',
          siteNotice: '',
          siteDescription: ''
        }
      }
    },
    created() {
      this.getSettingsInfo()
    },
    methods: {
      onSubmit() {
        const vm = this
        this.loading = true
        editSettings(this.form).then(response => {
          if (response.code === 0) {
            this.$message({
              message: '提交成功',
              center: true,
              onClose() {
                vm.getSettingsInfo()
                vm.loading = false
              }
            })
          }
        })
      },
      getSettingsInfo() {
        getSettings().then(res => {
          this.form = res.data
        })
      }
    },
    components: {}
  }
</script>
